<?php

namespace Frieza\Modules\Position\Controllers;

use App\Http\Controllers\Controller;
use Doraemon\service\position\PositionModule;
use Doraemon\tools\ImgUrl;
use Encore\Admin\Widgets\Form;
use Encore\Admin\Grid;
use Illuminate\Http\Request;


class Tab2ChannelController extends BaseController
{
    use BaseTrait;

    public function extendList(Grid $grid)
    {
        $grid->column('pos', '位置');
        $grid->column('title', '标题')->display(function () {
            $title = [];
            if ($this->big) $title[] = "大号标题:" . $this->big;
            if ($this->title) $title[] = "标题:" . $this->title;
            if ($this->sub_title) $title[] = "副标题:" . $this->sub_title;
            return implode('<br/>', $title);
        });
        $grid->column('icon_url', '图标')->image('', 100);
        $grid->column('ext_icon_url', '额外图标')->image('', 50);
    }

    public function extendSaveBaseInfo(Request $request): array
    {
        $big = $request->input("big", "");
        $title = $request->input("title", "");
        $sub_title = $request->input("sub_title", "");
        $icon_id = $request->input("icon_id", "");
        $small_icon_id = $request->input("small_icon_id", "");
        return ['pic_id' => json_encode(compact('big','title', 'sub_title','icon_id', 'small_icon_id'), JSON_UNESCAPED_UNICODE)];
    }

    public function beforeTitleForm(Form $form)
    {
        $seed = range(1, 20);
        $form->select('base.pos', '位置')->options(array_combine($seed, $seed));
        $form->text('big', '大号标题')->help('5.5.0开始生效');
        $form->text('title', '标题');
        $form->text('sub_title', '副标题')->help('5.5.0开始生效');
        $form->imgUpload('icon_id', '图标', false, ['imgType' => ImgUrl::APPTYPE_OP, 'imgSize' => ImgUrl::IMAGE_SIZE_OP_ORI]);
        $form->imgUpload('small_icon_id', '额外图标', false, ['imgType' => ImgUrl::APPTYPE_OP, 'imgSize' => ImgUrl::IMAGE_SIZE_OP_ORI]);
    }

}
